package day0727API;

public class Test9 {
    public static void main(String[] args) {
        Test9 s=new  Test9();
        Thread boss=new Thread(){
            public void run() {
                synchronized (s){
                    try {
                        System.out.println("线程Boss获取锁，开始运行");
                       // s.wait(); //consumer会运行
                        Thread.sleep(900000000);//consumer不会运行
                        System.out.println("线程Boss运行结束");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        };
        boss.start();

        Thread consumer=new Thread(()-> {
            synchronized (s){
                try {
                    while(true){
                        Thread.sleep(3000);
                        System.out.println("consumer运行");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
        consumer.start();
    }
}//boss线程如果先运行，到wait（）方法阻塞， 然后consumer线程运行
// (因为boss线程是通过wait阻塞的，会释放对象锁，同时同步监视器对象也会被释放，consumer线程就可以获取锁和同步监视器对象来运行)

